class Solution {
public:
    void preorder(TreeNode* root, vector<int>& ret)
    {
        if (root == nullptr) return;
        ret.push_back(root->val);
        preorder(root->left, ret);
        preorder(root->right, ret);
    }
    vector<int> preorderTraversal(TreeNode* root)
    {
        vector<int> ret;
        preorder(root, ret);
        return ret;
    }
};